<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="100px"
    >
      <el-form-item label="流程名称" prop="InstanceName">
        <el-input
          v-model="queryParams.InstanceName"
          placeholder="请输入流程名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流程类型" prop="BizObjectSchemaCode">
        <el-select
          v-model="queryParams.BizObjectSchemaCode"
          placeholder="请选择流程类型"
          clearable
          filterable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in workflowOptions"
            :key="item.url"
            :label="item.workflowName"
            :value="item.url"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="流程节点名称" prop="DisplayName">
        <el-input
          v-model="queryParams.DisplayName"
          placeholder="请输入流程节点名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驳回人" prop="UserName">
        <el-input
          v-model="queryParams.UserName"
          placeholder="请输入驳回人"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驳回时间" prop="CreatedTime">
        <el-date-picker
          v-model="queryParams.CreatedTime"
          type="daterange"
          range-separator="-"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 240px"
          size="small"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="驳回内容" prop="commentText">
        <el-input
          v-model="queryParams.commentText"
          placeholder="请输入驳回内容"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleSycn"
          >同步</el-button
        >
        <!--v-hasPermi="['system:no:export']"-->
      </el-col>
    </el-row>
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['projectWorkbench:businessOper:export']"
          >导出</el-button
        >
      </el-col>
    </el-row>
-->
    <el-table v-loading="loading" :data="rejectCommentList">
      <el-table-column label="流程名称" align="left" prop="InstanceName" />
      <el-table-column
        label="流程类型"
        width="200"
        align="center"
        prop="BizObjectSchemaCode"
      />
      <el-table-column
        label="流程节点名称"
        align="left"
        prop="DisplayName"
        width="150"
      />
      <el-table-column
        label="驳回人"
        align="center"
        prop="UserName"
        width="90"
      />
      <el-table-column
        label="驳回时间"
        align="center"
        prop="CreatedTime"
        width="150"
      />
      <el-table-column label="驳回内容" align="left" prop="commentText" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listBpmRejectComment,
  workflowList,
  syncRejectList,
} from "@/api/rejectComment/rejectComment";

export default {
  name: "BusinessOper",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 业务操作记录表格数据
      rejectCommentList: [],
      workflowOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        InstanceName: undefined,
        BizObjectSchemaCode: undefined,
        UserName: undefined,
        CreatedTime: undefined,
        commentText: undefined,
        DisplayName: undefined,
      },
    };
  },
  created() {
    Promise.all([this.getWorkflowList(), this.getList()]);
  },
  methods: {
    handleSycn(){
      var $this = this;
      syncRejectList().then(res=>{
        if(res.code===200 && res.data>=0){
          $this.getList();
        }
      });
    },
    /** 查询业务操作记录列表 */
    getList() {
      return new Promise((resolve, reject) => {
        this.loading = true;

        var reqParams = {
          pageNum: this.queryParams.pageNum,
          pageSize: this.queryParams.pageSize,
          InstanceName: this.queryParams.InstanceName,
          BizObjectSchemaCode: this.queryParams.BizObjectSchemaCode,
          UserName: this.queryParams.UserName,
          commentText: this.queryParams.commentText,
          DisplayName: this.queryParams.DisplayName,
        };

        if (this.queryParams.CreatedTime) {
          reqParams.beginCreatedTime = this.queryParams.CreatedTime[0];
          reqParams.endCreatedTime = this.queryParams.CreatedTime[1];
        }

        listBpmRejectComment(reqParams).then((res) => {
          if (res.code === 200) {
            this.rejectCommentList = res.data.resList;
            if (this.rejectCommentList) {
              var items = this.rejectCommentList;
              items.forEach((item) => {
                item.CreatedTime = this.renderTime(item.CreatedTime);
                var workflowOptions = this.workflowOptions;
                workflowOptions.forEach((it) => {
                  if (it.url === item.BizObjectSchemaCode) {
                    item.BizObjectSchemaCode = it.workflowName;
                  }
                });
              });
            }
            this.total = res.data.total;
            this.loading = false;
          }
        });
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有业务操作记录数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportBusinessOper(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        })
        .catch(function () {});
    },
    renderTime(date) {
      var dateee = new Date(date).toJSON();
      return new Date(+new Date(dateee) + 8 * 3600 * 1000)
        .toISOString()
        .replace(/T/g, " ")
        .replace(/\.[\d]{3}Z/, "");
    },
    getWorkflowList() {
      return new Promise((resolve, reject) => {
        workflowList().then((res) => {
          this.workflowOptions = res.data;
        });
      });
    },
  },
};
</script>